<template>
  <el-dialog
    title="设置状态"
    :visible="show"
    append-to-body
    @close="$emit('close')"
    width="240px">
    <el-select v-model="localStatus">
      <el-option
        v-for="d in $store.state.equipStatusList"
        :key="d.id"
        :label="d.name"
        :value="d.id"
      ></el-option>
    </el-select>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data(){
    return{
      localStatus:''
    }
  },
  props:{
    show:{
      type:Boolean,
      default:false
    },
    status:{
      type:String,
    },
    id:{
      type:String,
    },
  },
  created(){
    this.localStatus = this.status
  },
  watch:{
    status(){
      this.localStatus = this.status
    },
    show(val){
      //修改同样状态的两条数据时,status不变，检测不出来，可以通过监测show即弹窗的打开来修复
      if(val){
        this.localStatus = this.status;
      }
    }
  },
  methods:{
    submit(){
      this.axios.post('/equip-set',{
        status:this.localStatus,
        id:this.id
      }).then(data=>{
        if(!data.code){
          this.$message.success('状态设置成功')
          this.$emit('success')
        }
      })
    }
  }
}
</script>
